package com.quick.threadtest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName MianShi
 * @Description TODO
 * @Author Wangxin
 * @Date 2019-02-20 22:20
 * @Version 1.0
 **/
public class MianShi {
    public static volatile  int a =100;
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(4);
        for (int i = 0; i < 3; i++) {
            Th1 th1 = new Th1();
            service.execute(th1);
        }

        for (int i = 0; i < 2; i++) {
            Th2 th2 = new Th2();
            service.execute(th2);
        }

        System.out.println(a);
    }

}

class Th1 implements Runnable{

    @Override
    public void run() {
        ttt ttt = new ttt();
        ttt.add();
    }
}

class Th2 implements Runnable{

    @Override
    public void run() {
        ttt ttt = new ttt();
        ttt.m();
    }
}

class ttt{
    public void add(){
        synchronized (this){
            MianShi.a++;
        }
    }
    public void m(){
        synchronized (this){
            MianShi.a--;
        }
    }
}
